﻿// <copyright file="CredentialsProvider.cs" company="Soumya Chattopadhyay">
// Copyright (c) 2010 All Right Reserved
// </copyright>
// <disclaimer> This software is intented for educational purposes only and not for 
// commerical or prodution use. The software is provided "as is", without warranty 
// of any kind, express or implied, including but not limited to the warranties of 
// merchantability, fitness for a particular purpose and noninfringement. In no event 
// shall the author(s) or copyright holder(s) be liable for any claim, damages or other 
// liability, whether in an action of contract, tort or otherwise, arising from, out of 
// or in connection with the software or the use or other dealings in the software.
// </disclaimer>

namespace My.CodePlex.TFSExplorer
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.TeamFoundation.Client;

    /// <summary>
    /// The credentials provider
    /// </summary>
    public class CredentialsProvider : ICredentialsProvider
    {
        #region ICredentialsProvider Members

        /// <summary>
        /// Get the user credentials
        /// </summary>
        /// <param name="uri">A pointer to a null-terminated string that contains the name of the target for the credentials, typically a server name.</param>
        /// <param name="failedCredentials">Failed credentials</param>
        /// <returns>The user credentials</returns>
        System.Net.ICredentials ICredentialsProvider.GetCredentials(Uri uri, System.Net.ICredentials failedCredentials)
        {
            CREDUI_FLAGS flags = CREDUI_FLAGS.GENERIC_CREDENTIALS | CREDUI_FLAGS.EXPECT_CONFIRMATION | CREDUI_FLAGS.PERSIST;
            return CredentialHelper.GetCredentials(uri, "Connecting to Team Foundation Server", IntPtr.Zero, flags, failedCredentials);
        }

        /// <summary>
        /// Confirms the user credentials
        /// </summary>
        /// <param name="uri">A pointer to a null-terminated string that contains the name of the target for the credentials, typically a server name.</param>
        void ICredentialsProvider.NotifyCredentialsAuthenticated(Uri uri)
        {
            CredentialHelper.ConfirmCredentials(uri);
        }

        #endregion
    }
}
